{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--BOOK_INFORMATION-->\n",
    "<a href=\"https://user-images.githubusercontent.com/19553554/71825144-2d568180-30d6-11ea-8ee0-63c849cfd934.png\" target=\"_blank\"><img align=\"left\" style=\"width: 76px; height: 100px; background: white; padding: 1px; border: 1px solid black; margin-right:10px;\"></a>\n",
    "*pyecharts 是一个用于生成 Echarts 图表的类库。Echarts 是百度开源的一个数据可视化 JS 库。用 Echarts 生成的图可视化效果非常棒，为了与 Python 进行对接，方便在 Python 中直接使用数据生成图，于是有人开发出了这个项目[GitHub](https://github.com/pyecharts/pyecharts) .*\n",
    "\n",
    "*Note.建议本程序在参看https://github.com/pyecharts/pyecharts 的安装步骤后再运行； 本程序所有的例子都是从官方提供的样例代码[GitHub](https://github.com/pyecharts/pyecharts-gallery)中提取的,如果对某个API有疑问建议在IDE里面查看*\n",
    "\n",
    "*Echart类型图种大全:https://echarts.apache.org/examples/zh/#chart-type-line pyecharts图导入到ppt中的方法:https://baijiahao.baidu.com/s?id=1663839456876951842&wfr=spider&for=pc.*\n",
    "\n",
    "*作者: LBQ; 时间:2020/7/24. 邮箱:779660843@qq.com*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# XXIV.平行数据(Parallel)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/fisadm/anaconda3/envs/detectron2/lib/python3.7/site-packages/pyecharts/charts/chart.py:14: PendingDeprecationWarning: pyecharts 所有图表类型将在 v1.9.0 版本开始强制使用 ChartItem 进行数据项配置 :)\n",
      "  super().__init__(init_opts=init_opts)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"64c757cfaf154f27aeef5ffce981f013\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_64c757cfaf154f27aeef5ffce981f013 = echarts.init(\n",
       "                    document.getElementById('64c757cfaf154f27aeef5ffce981f013'), 'white', {renderer: 'canvas'});\n",
       "                var option_64c757cfaf154f27aeef5ffce981f013 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"parallel\",\n",
       "            \"coordinateSystem\": \"parallel\",\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 4,\n",
       "                \"opacity\": 0.5,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"data\": [\n",
       "                [\n",
       "                    12.99,\n",
       "                    100,\n",
       "                    82,\n",
       "                    \"Good\"\n",
       "                ],\n",
       "                [\n",
       "                    9.99,\n",
       "                    80,\n",
       "                    77,\n",
       "                    \"OK\"\n",
       "                ],\n",
       "                [\n",
       "                    20,\n",
       "                    120,\n",
       "                    60,\n",
       "                    \"Excellent\"\n",
       "                ]\n",
       "            ],\n",
       "            \"smooth\": false\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\": true\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"parallel\": {\n",
       "        \"left\": \"5%\",\n",
       "        \"right\": \"13%\",\n",
       "        \"bottom\": \"10%\",\n",
       "        \"top\": \"20%\"\n",
       "    },\n",
       "    \"parallelAxis\": [\n",
       "        {\n",
       "            \"dim\": 0,\n",
       "            \"name\": \"Price\"\n",
       "        },\n",
       "        {\n",
       "            \"dim\": 1,\n",
       "            \"name\": \"Net Weight\"\n",
       "        },\n",
       "        {\n",
       "            \"dim\": 2,\n",
       "            \"name\": \"Amount\"\n",
       "        },\n",
       "        {\n",
       "            \"dim\": 3,\n",
       "            \"name\": \"Score\",\n",
       "            \"type\": \"category\",\n",
       "            \"data\": [\n",
       "                \"Excellent\",\n",
       "                \"Good\",\n",
       "                \"OK\",\n",
       "                \"Bad\"\n",
       "            ]\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_64c757cfaf154f27aeef5ffce981f013.setOption(option_64c757cfaf154f27aeef5ffce981f013);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7f01442185c0>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pyecharts.options as opts\n",
    "from pyecharts.charts import Parallel\n",
    "\n",
    "\"\"\"\n",
    "Gallery 使用 pyecharts 1.1.0\n",
    "参考地址: https://echarts.baidu.com/examples/editor.html?c=parallel-simple\n",
    "\n",
    "目前无法实现的功能:\n",
    "\n",
    "1、\n",
    "\"\"\"\n",
    "\n",
    "parallel_axis = [\n",
    "    {\"dim\": 0, \"name\": \"Price\"},\n",
    "    {\"dim\": 1, \"name\": \"Net Weight\"},\n",
    "    {\"dim\": 2, \"name\": \"Amount\"},\n",
    "    {\n",
    "        \"dim\": 3,\n",
    "        \"name\": \"Score\",\n",
    "        \"type\": \"category\",\n",
    "        \"data\": [\"Excellent\", \"Good\", \"OK\", \"Bad\"],\n",
    "    },\n",
    "]\n",
    "\n",
    "data = [[12.99, 100, 82, \"Good\"], [9.99, 80, 77, \"OK\"], [20, 120, 60, \"Excellent\"]]\n",
    "\n",
    "\n",
    "c = (\n",
    "    Parallel()\n",
    "    .add_schema(schema=parallel_axis)#平行数据\n",
    "    .add(\n",
    "        series_name=\"\",\n",
    "        data=data,\n",
    "        linestyle_opts=opts.LineStyleOpts(width=4, opacity=0.5),\n",
    "    )\n",
    "    #.render(\"basic_parallel.html\")\n",
    ")\n",
    "c.load_javascript()\n",
    "c.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/fisadm/anaconda3/envs/detectron2/lib/python3.7/site-packages/pyecharts/charts/chart.py:14: PendingDeprecationWarning: pyecharts 所有图表类型将在 v1.9.0 版本开始强制使用 ChartItem 进行数据项配置 :)\n",
      "  super().__init__(init_opts=init_opts)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"623def9f091c4e76bdd7b6bee6c2094c\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_623def9f091c4e76bdd7b6bee6c2094c = echarts.init(\n",
       "                    document.getElementById('623def9f091c4e76bdd7b6bee6c2094c'), 'white', {renderer: 'canvas'});\n",
       "                var option_623def9f091c4e76bdd7b6bee6c2094c = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"parallel\",\n",
       "            \"coordinateSystem\": \"parallel\",\n",
       "            \"lineStyle\": {\n",
       "                \"show\": true,\n",
       "                \"width\": 1,\n",
       "                \"opacity\": 1,\n",
       "                \"curveness\": 0,\n",
       "                \"type\": \"solid\"\n",
       "            },\n",
       "            \"name\": \"parallel\",\n",
       "            \"data\": [\n",
       "                [\n",
       "                    1,\n",
       "                    91,\n",
       "                    45,\n",
       "                    125,\n",
       "                    0.82,\n",
       "                    34,\n",
       "                    23,\n",
       "                    \"\\u826f\"\n",
       "                ],\n",
       "                [\n",
       "                    2,\n",
       "                    65,\n",
       "                    27,\n",
       "                    78,\n",
       "                    0.86,\n",
       "                    45,\n",
       "                    29,\n",
       "                    \"\\u826f\"\n",
       "                ],\n",
       "                [\n",
       "                    3,\n",
       "                    83,\n",
       "                    60,\n",
       "                    84,\n",
       "                    1.09,\n",
       "                    73,\n",
       "                    27,\n",
       "                    \"\\u826f\"\n",
       "                ],\n",
       "                [\n",
       "                    4,\n",
       "                    109,\n",
       "                    81,\n",
       "                    121,\n",
       "                    1.28,\n",
       "                    68,\n",
       "                    51,\n",
       "                    \"\\u8f7b\\u5ea6\\u6c61\\u67d3\"\n",
       "                ],\n",
       "                [\n",
       "                    5,\n",
       "                    106,\n",
       "                    77,\n",
       "                    114,\n",
       "                    1.07,\n",
       "                    55,\n",
       "                    51,\n",
       "                    \"\\u8f7b\\u5ea6\\u6c61\\u67d3\"\n",
       "                ],\n",
       "                [\n",
       "                    6,\n",
       "                    109,\n",
       "                    81,\n",
       "                    121,\n",
       "                    1.28,\n",
       "                    68,\n",
       "                    51,\n",
       "                    \"\\u8f7b\\u5ea6\\u6c61\\u67d3\"\n",
       "                ],\n",
       "                [\n",
       "                    7,\n",
       "                    106,\n",
       "                    77,\n",
       "                    114,\n",
       "                    1.07,\n",
       "                    55,\n",
       "                    51,\n",
       "                    \"\\u8f7b\\u5ea6\\u6c61\\u67d3\"\n",
       "                ],\n",
       "                [\n",
       "                    8,\n",
       "                    89,\n",
       "                    65,\n",
       "                    78,\n",
       "                    0.86,\n",
       "                    51,\n",
       "                    26,\n",
       "                    \"\\u826f\"\n",
       "                ],\n",
       "                [\n",
       "                    9,\n",
       "                    53,\n",
       "                    33,\n",
       "                    47,\n",
       "                    0.64,\n",
       "                    50,\n",
       "                    17,\n",
       "                    \"\\u826f\"\n",
       "                ],\n",
       "                [\n",
       "                    10,\n",
       "                    80,\n",
       "                    55,\n",
       "                    80,\n",
       "                    1.01,\n",
       "                    75,\n",
       "                    24,\n",
       "                    \"\\u826f\"\n",
       "                ],\n",
       "                [\n",
       "                    11,\n",
       "                    117,\n",
       "                    81,\n",
       "                    124,\n",
       "                    1.03,\n",
       "                    45,\n",
       "                    24,\n",
       "                    \"\\u8f7b\\u5ea6\\u6c61\\u67d3\"\n",
       "                ],\n",
       "                [\n",
       "                    12,\n",
       "                    99,\n",
       "                    71,\n",
       "                    142,\n",
       "                    1.1,\n",
       "                    62,\n",
       "                    42,\n",
       "                    \"\\u826f\"\n",
       "                ],\n",
       "                [\n",
       "                    13,\n",
       "                    95,\n",
       "                    69,\n",
       "                    130,\n",
       "                    1.28,\n",
       "                    74,\n",
       "                    50,\n",
       "                    \"\\u826f\"\n",
       "                ],\n",
       "                [\n",
       "                    14,\n",
       "                    116,\n",
       "                    87,\n",
       "                    131,\n",
       "                    1.47,\n",
       "                    84,\n",
       "                    40,\n",
       "                    \"\\u8f7b\\u5ea6\\u6c61\\u67d3\"\n",
       "                ]\n",
       "            ],\n",
       "            \"smooth\": false\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"parallel\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"parallel\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"parallel\": {\n",
       "        \"left\": \"5%\",\n",
       "        \"right\": \"13%\",\n",
       "        \"bottom\": \"10%\",\n",
       "        \"top\": \"20%\"\n",
       "    },\n",
       "    \"parallelAxis\": [\n",
       "        {\n",
       "            \"dim\": 0,\n",
       "            \"name\": \"data\",\n",
       "            \"scale\": false\n",
       "        },\n",
       "        {\n",
       "            \"dim\": 1,\n",
       "            \"name\": \"AQI\",\n",
       "            \"scale\": false\n",
       "        },\n",
       "        {\n",
       "            \"dim\": 2,\n",
       "            \"name\": \"PM2.5\",\n",
       "            \"scale\": false\n",
       "        },\n",
       "        {\n",
       "            \"dim\": 3,\n",
       "            \"name\": \"PM10\",\n",
       "            \"scale\": false\n",
       "        },\n",
       "        {\n",
       "            \"dim\": 4,\n",
       "            \"name\": \"CO\",\n",
       "            \"scale\": false\n",
       "        },\n",
       "        {\n",
       "            \"dim\": 5,\n",
       "            \"name\": \"NO2\",\n",
       "            \"scale\": false\n",
       "        },\n",
       "        {\n",
       "            \"dim\": 6,\n",
       "            \"name\": \"CO2\",\n",
       "            \"scale\": false\n",
       "        },\n",
       "        {\n",
       "            \"dim\": 7,\n",
       "            \"name\": \"\\u7b49\\u7ea7\",\n",
       "            \"data\": [\n",
       "                \"\\u4f18\",\n",
       "                \"\\u826f\",\n",
       "                \"\\u8f7b\\u5ea6\\u6c61\\u67d3\",\n",
       "                \"\\u4e2d\\u5ea6\\u6c61\\u67d3\",\n",
       "                \"\\u91cd\\u5ea6\\u6c61\\u67d3\",\n",
       "                \"\\u4e25\\u91cd\\u6c61\\u67d3\"\n",
       "            ],\n",
       "            \"type\": \"category\",\n",
       "            \"scale\": false\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"Parallel-Category\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_623def9f091c4e76bdd7b6bee6c2094c.setOption(option_623def9f091c4e76bdd7b6bee6c2094c);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x7f014423ae80>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Parallel\n",
    "\n",
    "data = [\n",
    "    [1, 91, 45, 125, 0.82, 34, 23, \"良\"],\n",
    "    [2, 65, 27, 78, 0.86, 45, 29, \"良\"],\n",
    "    [3, 83, 60, 84, 1.09, 73, 27, \"良\"],\n",
    "    [4, 109, 81, 121, 1.28, 68, 51, \"轻度污染\"],\n",
    "    [5, 106, 77, 114, 1.07, 55, 51, \"轻度污染\"],\n",
    "    [6, 109, 81, 121, 1.28, 68, 51, \"轻度污染\"],\n",
    "    [7, 106, 77, 114, 1.07, 55, 51, \"轻度污染\"],\n",
    "    [8, 89, 65, 78, 0.86, 51, 26, \"良\"],\n",
    "    [9, 53, 33, 47, 0.64, 50, 17, \"良\"],\n",
    "    [10, 80, 55, 80, 1.01, 75, 24, \"良\"],\n",
    "    [11, 117, 81, 124, 1.03, 45, 24, \"轻度污染\"],\n",
    "    [12, 99, 71, 142, 1.1, 62, 42, \"良\"],\n",
    "    [13, 95, 69, 130, 1.28, 74, 50, \"良\"],\n",
    "    [14, 116, 87, 131, 1.47, 84, 40, \"轻度污染\"],\n",
    "]\n",
    "c2 = (\n",
    "    Parallel()\n",
    "    .add_schema(\n",
    "        [\n",
    "            opts.ParallelAxisOpts(dim=0, name=\"data\"),\n",
    "            opts.ParallelAxisOpts(dim=1, name=\"AQI\"),\n",
    "            opts.ParallelAxisOpts(dim=2, name=\"PM2.5\"),\n",
    "            opts.ParallelAxisOpts(dim=3, name=\"PM10\"),\n",
    "            opts.ParallelAxisOpts(dim=4, name=\"CO\"),\n",
    "            opts.ParallelAxisOpts(dim=5, name=\"NO2\"),\n",
    "            opts.ParallelAxisOpts(dim=6, name=\"CO2\"),\n",
    "            opts.ParallelAxisOpts(\n",
    "                dim=7,\n",
    "                name=\"等级\",\n",
    "                type_=\"category\",\n",
    "                data=[\"优\", \"良\", \"轻度污染\", \"中度污染\", \"重度污染\", \"严重污染\"],\n",
    "            ),\n",
    "        ]\n",
    "    )\n",
    "    .add(\"parallel\", data)\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"Parallel-Category\"))\n",
    "   # .render(\"parallel_category.html\")\n",
    ")\n",
    "c2.load_javascript()\n",
    "c2.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
